package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 菜品数据层接口
 */
@Mapper
public interface DishMapper {

    /**
     * 新增菜品
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void saveDish(Dish dish);

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 通过菜品ID获取当前的菜品信息
     * @param id
     * @return
     */
    @Select("select * from dish where  id = #{id}")
    Dish selectDishById(Long id);

    /**
     * 更新菜品信息
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void updateDish(Dish dish);

    /**
     * 通过分类ID查询菜品信息
     * @param id
     * @return
     */
    @Select("select * from dish where category_id = #{id}")
    List<Dish> selectDishByCategoryId(Long id);

    /**
     * 通过菜品ID删除菜品
     * @param id
     */
    @Delete("delete from dish where id = #{id}")
    void deleteDishById(Long id);

    /**
     * 通过菜品状态查询此状态的菜品
     * @param disable
     * @return
     */
    List<Dish> startOrStop(Integer disable);

    /**
     * 通过菜品分类获取所有的菜品信息
     * @param categoryId
     * @return
     */
    @Select("select d.*,c.name as 'categoryName' from dish d left join category c on d.category_id = c.id where d.category_id = #{categoryId}")
    List<DishVO> selectDishByCategoryIdGetVo(Long categoryId);
}
